OSTYPE ?= linux
CPPFILES_CPU = face_detection_cpu.cpp
CPPFILES_GPU = face_detection_gpu.cpp face_detection_gpu_main.cpp 
CUFILES_GPU = face_detection_gpu_core.cu 

CUDA_INSTALL_PATH ?= /usr/local/cuda
CUDA_SDK_INSTALL_PATH ?= /home/alpha/sdk/gpusdk3.1
#CUDA_INSTALL_PATH ?= ~/develop/compress/cuda2.2
#CUDA_SDK_INSTALL_PATH ?= ~/develop/compress/cudasdk2.21/sdk
C++ = g++
C = gcc
NVCC = $(CUDA_INSTALL_PATH)/bin/nvcc

SRCDIR = .
BINDIR = ./bin
OBJDIR = ./obj
#OPENCV_OBJDIR = ./OpenCV/obj

#INCLUDES = -I OpenCV/cv -I OpenCV/include/opencv -I OpenCV/3rdparty/include -I . -I $(CUDA_INSTALL_PATH)/include -I $(CUDA_SDK_INSTALL_PATH)/C/common/inc
INCLUDES = `pkg-config --cflags --libs opencv` -I . -I $(CUDA_INSTALL_PATH)/include -I $(CUDA_SDK_INSTALL_PATH)/C/common/inc

LIB_CPU = -lpthread
LIB_GPU = -L $(CUDA_INSTALL_PATH)/lib -L $(CUDA_SDK_INSTALL_PATH)/C/lib -lcudart -lcutil -lpthread

ifeq (,$(findstring darwin,$(OSTYPE)))
	LIB_CPU += -lrt
	LIB_GPU += -lrt
endif


TARGET_CPU = $(BINDIR)/face_detection_cpu
TARGET_GPU = $(BINDIR)/face_detection_gpu

OBJS_CPU_MAIN = $(patsubst %.cpp,$(OBJDIR)/%.cpp.o,$(notdir $(CPPFILES_CPU))) 
OBJS_CPU = $(OBJS_CPU_MAIN) `pkg-config --libs opencv` #$(OPENCV_OBJDIR)/*.o
OBJS_GPU_MAIN += $(patsubst %.cpp,$(OBJDIR)/%.cpp.o,$(notdir $(CPPFILES_GPU))) 
OBJS_GPU_MAIN += $(patsubst %.cu,$(OBJDIR)/%.cu.o,$(notdir $(CUFILES_GPU)))
OBJS_GPU = $(OBJS_GPU_MAIN) `pkg-config --cflags --libs opencv` #$(OPENCV_OBJDIR)/*.o

#all: $(OPENCV_OBJDIR)/.exist $(TARGET_CPU) $(TARGET_GPU) 
all: $(TARGET_CPU) $(TARGET_GPU)
$(TARGET_CPU): $(OBJDIR)/.exist $(BINDIR)/.exist $(OBJS_CPU_MAIN)
	$(C++) -o $(TARGET_CPU) $(OBJS_CPU) $(LIB_CPU) 

$(TARGET_GPU): $(OBJDIR)/.exist $(BINDIR)/.exist $(OBJS_GPU_MAIN)
	$(NVCC) -o $(TARGET_GPU) $(OBJS_GPU) $(LIB_GPU)

$(OBJDIR)/%.cpp.o: $(SRCDIR)/%.cpp
	$(C++) $(INCLUDES) -c $< -o $@

$(OBJDIR)/%.cu.o: $(SRCDIR)/%.cu
	$(NVCC) $(INCLUDES) -c $< -o $@

$(OBJDIR)/.exist:
	mkdir -p $(OBJDIR)
	touch $(OBJDIR)/.exist

$(BINDIR)/.exist:
	mkdir -p $(BINDIR)
	touch $(BINDIR)/.exist

#$(OPENCV_OBJDIR)/.exist:
#	make -C OpenCV

clean: 
	rm -f $(TARGET_CPU) $(TARGET_GPU) $(OBJS_CPU_MAIN) $(OBJS_GPU_MAIN) #$(OPENCV_OBJDIR)/.exist
